from ..extensions import db
from datetime import datetime

class SignupRecord(db.Model):
    __tablename__ = 'signup_records'
    
    id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"), primary_key=True, autoincrement=True, comment='主键ID')
    name = db.Column(db.String(100), nullable=False, comment='姓名')
    phone = db.Column(db.String(20), nullable=False, comment='手机号')
    activity_id = db.Column(db.BigInteger().with_variant(db.Integer, "sqlite"), nullable=False, comment='活动ID（逻辑外键）')
    signup_time = db.Column(db.DateTime, nullable=False, comment='报名时间')
    create_time = db.Column(db.DateTime, nullable=False, default=datetime.utcnow, comment='创建时间')
    
    def to_dict(self):
        return {
            'id': self.id,
            'name': self.name,
            'phone': self.phone,
            'activity_id': self.activity_id,
            'signup_time': str(self.signup_time) if self.signup_time else None,
            'create_time': str(self.create_time) if self.create_time else None
        }